# 第一阶段：构建WebUI
FROM node:20-alpine AS web-builder

WORKDIR /webui
COPY webui/package*.json ./
RUN npm ci
COPY webui .
RUN npm run build

# 第二阶段：构建Server
FROM node:20-alpine

WORKDIR /app
COPY server/package*.json ./
RUN npm ci --only=production
COPY server .

# 从web-builder阶段复制构建好的webui文件到server的public目录
COPY --from=web-builder /webui/dist ./public

# 设置环境变量
ENV NODE_ENV=production

EXPOSE ${PORT}
CMD ["node", "server.js"]